/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.trandio.manager;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.naming.NamingException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.trandio.dao.LiquidacionDAO;
import org.trandio.dao.LiquidacionInterface;
import org.trandio.dao.MedicoDAO;
import org.trandio.dao.MedicoInterface;
import org.trandio.model.FacturaVO;
import org.trandio.model.MedicoVO;

/**
 *
 * @author root
 */
public class Preliquidacion extends HttpServlet {

    /**
     * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */

    LiquidacionInterface liquidacionInterface;
    MedicoInterface medicoInterface;
    FacturaVO  facturaVO;
    MedicoVO medicoVO;


    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        try {

            liquidacionInterface = new LiquidacionDAO();
            medicoInterface = new MedicoDAO();

            String idfactura = request.getParameter("idfact");
            String descprestador = "";
            String descentidad = "";
            String numfactura = "FDV"+idfactura;
            String fecha = "";
            String paciente = "";
            String medico = request.getParameter("idmedico");
            String vrpagar = request.getParameter("tpagar");
            String efectivo = "0.0";
            String descuento = "0.0";
            
            try {
                //traer datos de la factura
                facturaVO = liquidacionInterface.consultarFactura(idfactura);
                medicoVO = medicoInterface.getMedico(Integer.parseInt(medico));
            } catch (SQLException ex) {
                Logger.getLogger(Preliquidacion.class.getName()).log(Level.SEVERE, null, ex);
            } catch (NamingException ex) {
                Logger.getLogger(Preliquidacion.class.getName()).log(Level.SEVERE, null, ex);
            }



                descprestador = facturaVO.getDescprestador();
                descentidad = facturaVO.getDescentidad();
                fecha = facturaVO.getFecha();
                paciente = facturaVO.getPaciente();







            out.println("<html>");
            out.println("<head>");
            out.println("<title>Liquidaci&oacute;n Factura</title>");

            /*
            out.println("<style>");
            out.println("table.stats{text-align: center;font-family: Verdana, Geneva, Arial, Helvetica, sans-serif ;" +
                    "font-weight: normal;font-size: 11px;color: #fff;width: 480px;background-color: #666;" +
                    "border: 0px;border-collapse: collapse;border-spacing: 0px;}" +
                    "table.stats td{background-color: #CCC;color: #000;padding: 4px;text-align: left;border: 1px #fff solid;-moz-border-radius: 3px 3px 3px 3px;}" +
                    "table.stats td.hed{background-color: #666;color: #fff;padding: 4px;text-align: left;" +
                    "border-bottom: 2px #fff solid;font-size: 12px;font-weight: bold;} ");
            out.println("</style>");
            */


            out.println("</head>");
            out.println("<body>");


            out.println("<table width='100%' align='center'>");

            out.println("<tr>");
            out.println("<td class='ui-widget-header' align='center' colspan='2'>RESUM&Eacute;N LIQUIDACI&Oacute;N DE FACTURA</td>");
            out.println("</tr>");

            out.println("<tr>");out.println("<td>Prestador</td>");out.println("<td>"+descprestador+"</td>");out.println("</tr>");
            out.println("<tr>");out.println("<td>Aseguradora</td>");out.println("<td>"+descentidad+"</td>");out.println("</tr>");
            out.println("<tr>");out.println("<td>No. Factura</td>");out.println("<td>"+numfactura+"</td>");out.println("</tr>");
            out.println("<tr>");out.println("<td>Fecha</td>");out.println("<td>"+fecha+"</td>");out.println("</tr>");
            out.println("<tr>");out.println("<td>Paciente</td>");out.println("<td>"+paciente+"</td>");out.println("</tr>");
            out.println("<tr>");out.println("<td>Medico</td>");out.println("<td>"+medicoVO.getNombre()+"</td>");out.println("</tr>");
            out.println("<tr>");out.println("<td>Vr. Pagar Paciente</td>");
            out.println("<td><input readonly value='"+vrpagar+"' type='text'/></td>");
            out.println("</tr>");
            out.println("<tr>");out.println("<td>Vr. Efectivo</td>");
            out.println("<td><input value='"+vrpagar+"' type='text'/></td>");
            out.println("</tr>");
            out.println("<tr>");out.println("<td>Vr. Descuento</td>");
            out.println("<td><input value='"+descuento+"' type='text'/></td>");
            out.println("</tr>");
            out.println("<tr>");
            //out.println("<td class='hed' colspan='2' align='center'><button onclick='window.opener.imprimirFactura("+idfactura+")' id='btnimprimir'>Imprimir Factura</button></td>");
            out.println("</tr>");

            out.println("</table>");



            out.println("</body>");
            out.println("</html>");





        } finally {
            out.close();
        }
    }

    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /**
     * Handles the HTTP <code>GET</code> method.
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        processRequest(request, response);
    }

    /**
     * Handles the HTTP <code>POST</code> method.
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        processRequest(request, response);
    }

    /**
     * Returns a short description of the servlet.
     * @return a String containing servlet description
     */
    @Override
    public String getServletInfo() {
        return "Short description";
    }// </editor-fold>

}
